import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:打家劫舍(二)
 * User: wangxin
 * Date: 2025-02-10
 * Time: 21:06
 */
public class Test2 {
    public int rob (int[] nums) {
        // write code here
        int n = nums.length;
        int[] dp = new int[n + 1];
        dp[1] = nums[0];
        for(int i = 2;i < n;i++){
            dp[i] = Math.max(dp[i-1],(dp[i-2]+nums[i-1]));
        }
        int res = dp[n-1];
        Arrays.fill(dp,0);
        dp[1] = 0;
        for(int i = 2;i <= n;i++){
            dp[i] = Math.max(dp[i-1],(dp[i-2]+nums[i-1]));
        }
        res = Math.max(res,dp[n]);
        return res;
    }
}
